# 1.打开浏览器
import os
import time

from selenium import webdriver
from selenium.webdriver.chrome.service import Service
from selenium.webdriver.common.by import By

service = Service(executable_path=r'E:\python\pythonshuju\chromedriver.exe')
driver = webdriver.Chrome(service=service)  #创建浏览器对象
# 2.输入访问地址（URL）
driver.get("http://121.43.169.97:8848/pageA.html")
# 3.页面信息操作
# 1). 填写注册信息
driver.find_element(By.CSS_SELECTOR,"#userA").send_keys("admin")
# 2). 截图保存
# 调用截屏方法
driver.get_screenshot_as_file("img/admin.png")

# 动态获取文件名称，使用时间戳
# driver.get_screenshot_as_file("../img/%s.png" %(time.strftime("%Y_%m_%d_%H_%M_%S")))
driver.get_screenshot_as_file("img/{}.png".format(time.strftime("%Y_%m_%d_%H_%M_%S")))


# 4.关闭/退出浏览器
driver.quit()